package com.qf.j2102.service.impl;


import com.qf.j2102.mapper.SysUserMapper;
import com.qf.j2102.po.SysUser;
import com.qf.j2102.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper userDao;

    @Override
    public SysUser findByName(String tel, String password) {

        SysUser users = userDao.selectByTel(tel);
        if(users == null) {
            throw new RuntimeException("you not register");
        }
        if (!users.getPassword().equals(password)) {
            throw new RuntimeException("password wrong!");
        }

        return users;
    }

    @Override
    public void addUser(SysUser user) {

        try {
            userDao.insertSelective(user);
        } catch (Exception e) {
            throw new RuntimeException("success！");
        }

    }

    @Override
    public SysUser findUserById(Integer id) {

        SysUser user = userDao.selectByPrimaryKey(id);

        return user;
    }

    @Override
    public void update(SysUser user) {

        userDao.updateByPrimaryKeySelective(user);


    }

    @Override
    public void del(int id) {
        userDao.deluser(id);
    }


}
